

<!DOCTYPE html>
<html lang="zh_CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/fx-blog/img/ChenCat.png">
  <link rel="icon" href="/fx-blog/img/ChenCat.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="Ray_Hughes">
  <meta name="keywords" content="">
  
    <meta name="description" content="金砖国家职业技能大赛 省选拔赛有感叙述今天进行了金砖国家职业技能大赛的吉林省选拔赛 进行期间总结了一些方法 也发现了一些不足之处 接下来进行列举 希望对你的开发有所帮助 方法 与 坑列表对图片引用 上图中 出现了 学校logo图片 我首先采用了分析法 打开 F12 分析其他图片的显示链接 发现图片都走的是 http:&#x2F;&#x2F;localhost&#x2F;dev-api&#x2F;profile&#x2F;upload&#x2F;  然后顺藤">
<meta property="og:type" content="article">
<meta property="og:title" content="8-26比赛感悟">
<meta property="og:url" content="https://ray_hughes.gitee.io/fx-blog/2023/08/27/8-26%E6%AF%94%E8%B5%9B%E6%84%9F%E6%82%9F/index.html">
<meta property="og:site_name" content="枫溪的山谷">
<meta property="og:description" content="金砖国家职业技能大赛 省选拔赛有感叙述今天进行了金砖国家职业技能大赛的吉林省选拔赛 进行期间总结了一些方法 也发现了一些不足之处 接下来进行列举 希望对你的开发有所帮助 方法 与 坑列表对图片引用 上图中 出现了 学校logo图片 我首先采用了分析法 打开 F12 分析其他图片的显示链接 发现图片都走的是 http:&#x2F;&#x2F;localhost&#x2F;dev-api&#x2F;profile&#x2F;upload&#x2F;  然后顺藤">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://ray_hughes.gitee.io/fx-blog/img/blog/QQ%E6%88%AA%E5%9B%BE20230826205605.png">
<meta property="og:image" content="https://ray_hughes.gitee.io/fx-blog/img/blog/8-26%E6%AF%94%E8%B5%9B%E6%84%9F%E6%82%9F/image-20230826210512061.png">
<meta property="og:image" content="https://ray_hughes.gitee.io/fx-blog/img/blog/8-26%E6%AF%94%E8%B5%9B%E6%84%9F%E6%82%9F/image-20230826210709858.png">
<meta property="og:image" content="https://ray_hughes.gitee.io/fx-blog/img/blog/8-26%E6%AF%94%E8%B5%9B%E6%84%9F%E6%82%9F/image-20230826211122435.png">
<meta property="article:published_time" content="2023-08-27T04:52:14.000Z">
<meta property="article:modified_time" content="2023-09-05T08:23:50.821Z">
<meta property="article:author" content="Ray_Hughes">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://ray_hughes.gitee.io/fx-blog/img/blog/QQ%E6%88%AA%E5%9B%BE20230826205605.png">
  
  
  
  <title>8-26比赛感悟 - 枫溪的山谷</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/fx-blog/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/fx-blog/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/fx-blog/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"ray_hughes.gitee.io","root":"/fx-blog/","version":"1.9.5-a","typing":{"enable":true,"typeSpeed":60,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":{"measurement_id":null},"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/fx-blog/local-search.xml","include_content_in_search":true};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/fx-blog/js/utils.js" ></script>
  <script  src="/fx-blog/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 7.0.0-rc2"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/fx-blog/">
      <strong>枫溪的山谷</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/fx-blog/">
                <i class="iconfont icon-home-fill"></i>
                <span>主页</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/fx-blog/categories/%E5%BC%80%E5%8F%91/">
                <i class="iconfont icon-code"></i>
                <span>开发心得</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/fx-blog/categories/%E6%8F%92%E4%BB%B6/">
                <i class="iconfont icon-th-large"></i>
                <span>插件</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/fx-blog/archives/">
                <i class="iconfont icon-archive-fill"></i>
                <span>归档</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/fx-blog/categories/">
                <i class="iconfont icon-category-fill"></i>
                <span>分类</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" target="_blank" rel="noopener" href="http://maplefx.top:6520/fastsave">
                <i class="iconfont icon-plan"></i>
                <span>资源站</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/fx-blog/about/">
                <i class="iconfont icon-user-fill"></i>
                <span>关于</span>
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/fx-blog/links/">
                <i class="iconfont icon-link-fill"></i>
                <span>友链</span>
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              <i class="iconfont icon-search"></i>
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">
              <i class="iconfont icon-dark" id="color-toggle-icon"></i>
            </a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('https://s1.ax1x.com/2023/09/05/pPrb1ot.png') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="8-26比赛感悟"></span>
          
        </div>

        
          
  <div class="mt-3">
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2023-08-26 20:52" pubdate>
          2023年8月26日 晚上
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          23k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          189 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <h1 id="seo-header">8-26比赛感悟</h1>
            
            
              <div class="markdown-body">
                
                <h1 id="金砖国家职业技能大赛-省选拔赛有感"><a href="#金砖国家职业技能大赛-省选拔赛有感" class="headerlink" title="金砖国家职业技能大赛 省选拔赛有感"></a>金砖国家职业技能大赛 省选拔赛有感</h1><h2 id="叙述"><a href="#叙述" class="headerlink" title="叙述"></a>叙述</h2><p>今天进行了金砖国家职业技能大赛的吉林省选拔赛</p>
<p>进行期间总结了一些方法 也发现了一些不足之处</p>
<p>接下来进行列举 希望对你的开发有所帮助</p>
<h2 id="方法-与-坑"><a href="#方法-与-坑" class="headerlink" title="方法 与 坑"></a>方法 与 坑</h2><h3 id="列表对图片引用"><a href="#列表对图片引用" class="headerlink" title="列表对图片引用"></a>列表对图片引用</h3><p><img src="/fx-blog/img/blog/QQ%E6%88%AA%E5%9B%BE20230826205605.png" srcset="/fx-blog/img/loading.gif" lazyload alt="比赛过程中截图"></p>
<p>上图中 出现了 学校logo图片</p>
<p>我首先采用了分析法 打开 F12 分析其他图片的显示链接</p>
<p>发现图片都走的是 <a target="_blank" rel="noopener" href="http://localhost/dev-api/profile/upload/">http://localhost/dev-api/profile/upload/</a></p>
<p><img src="/fx-blog/img/blog/8-26%E6%AF%94%E8%B5%9B%E6%84%9F%E6%82%9F/image-20230826210512061.png" srcset="/fx-blog/img/loading.gif" lazyload alt="image-20230826210512061"></p>
<p>然后顺藤摸瓜 找到后端里配置的文件上传位置</p>
<p><img src="/fx-blog/img/blog/8-26%E6%AF%94%E8%B5%9B%E6%84%9F%E6%82%9F/image-20230826210709858.png" srcset="/fx-blog/img/loading.gif" lazyload alt="image-20230826210709858"></p>
<p>接下来我就编写了一个方法 进行对应位置读取</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;el-table-column label=&quot;图片上传&quot; align=&quot;center&quot; prop=&quot;imagersUpload&quot;&gt;<br>        &lt;template slot-scope=&quot;scope&quot;&gt;<br>          &lt;img class=&quot;img-input&quot; :src=&quot;parseImg(scope.row.imagersUpload)&quot;&gt;<br>        &lt;/template&gt;<br>&lt;/el-table-column&gt;<br></code></pre></td></tr></table></figure>

<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><code class="hljs javascript"><span class="hljs-title function_">parseImg</span>(<span class="hljs-params">src</span>) &#123;<br>      <span class="hljs-keyword">if</span> (src == <span class="hljs-literal">null</span>) &#123;<br>        <span class="hljs-keyword">return</span> <span class="hljs-string">&#x27;/static/img/404.a57b6f31.png&#x27;</span><br>      &#125;<br>      <span class="hljs-keyword">return</span> <span class="hljs-string">`/dev-api<span class="hljs-subst">$&#123;src&#125;</span>`</span><br>&#125;,<br></code></pre></td></tr></table></figure>



<p>虽然显示了 图片 但是并不是最优解决方案</p>
<p>因为我在比赛后半段发现了他框架中带的组件…</p>
<p><img src="/fx-blog/img/blog/8-26%E6%AF%94%E8%B5%9B%E6%84%9F%E6%82%9F/image-20230826211122435.png" srcset="/fx-blog/img/loading.gif" lazyload alt="image-20230826211122435"></p>
<p>使用这个框架就可以快速的设置图片…</p>
<h3 id="对于组件挂钩"><a href="#对于组件挂钩" class="headerlink" title="对于组件挂钩"></a>对于组件挂钩</h3><p>比赛中要求使用Echarts进行绘制图表</p>
<p>但是Echatrs对vue兼容需要新建一个组件 然后监听他的size变化</p>
<p>我虽然加上了组件 但是并未注册到全局 所以无法调用…</p>
<p>很是无语 接下来贴上组件注册写法</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;template&gt;<br>  &lt;div :id=&quot;id&quot; :class=&quot;className&quot; :style=&quot;&#123;height:height,width:width&#125;&quot; /&gt;<br>&lt;/template&gt;<br><br>&lt;script&gt;<br>import echarts from &#x27;echarts&#x27;<br>import resize from &#x27;./mixins/resize&#x27;<br><br>export default &#123;<br>  mixins: [resize],<br>  props: &#123;<br>    className: &#123;<br>      type: String,<br>      default: &#x27;chart&#x27;<br>    &#125;,<br>    id: &#123;<br>      type: String,<br>      default: &#x27;chart&#x27;<br>    &#125;,<br>    width: &#123;<br>      type: String,<br>      default: &#x27;200px&#x27;<br>    &#125;,<br>    height: &#123;<br>      type: String,<br>      default: &#x27;200px&#x27;<br>    &#125;<br>  &#125;,<br>  data() &#123;<br>    return &#123;<br>      chart: null<br>    &#125;<br>  &#125;,<br>  mounted() &#123;<br>    this.initChart()<br>  &#125;,<br>  beforeDestroy() &#123;<br>    if (!this.chart) &#123;<br>      return<br>    &#125;<br>    this.chart.dispose()<br>    this.chart = null<br>  &#125;,<br>  methods: &#123;<br>    initChart() &#123;<br>      this.chart = echarts.init(document.getElementById(this.id))<br><br>      this.chart.setOption(&#123;<br>        backgroundColor: &#x27;#394056&#x27;,<br>        title: &#123;<br>          top: 20,<br>          text: &#x27;Requests&#x27;,<br>          textStyle: &#123;<br>            fontWeight: &#x27;normal&#x27;,<br>            fontSize: 16,<br>            color: &#x27;#F1F1F3&#x27;<br>          &#125;,<br>          left: &#x27;1%&#x27;<br>        &#125;,<br>        tooltip: &#123;<br>          trigger: &#x27;axis&#x27;,<br>          axisPointer: &#123;<br>            lineStyle: &#123;<br>              color: &#x27;#57617B&#x27;<br>            &#125;<br>          &#125;<br>        &#125;,<br>        legend: &#123;<br>          top: 20,<br>          icon: &#x27;rect&#x27;,<br>          itemWidth: 14,<br>          itemHeight: 5,<br>          itemGap: 13,<br>          data: [&#x27;CMCC&#x27;, &#x27;CTCC&#x27;, &#x27;CUCC&#x27;],<br>          right: &#x27;4%&#x27;,<br>          textStyle: &#123;<br>            fontSize: 12,<br>            color: &#x27;#F1F1F3&#x27;<br>          &#125;<br>        &#125;,<br>        grid: &#123;<br>          top: 100,<br>          left: &#x27;2%&#x27;,<br>          right: &#x27;2%&#x27;,<br>          bottom: &#x27;2%&#x27;,<br>          containLabel: true<br>        &#125;,<br>        xAxis: [&#123;<br>          type: &#x27;category&#x27;,<br>          boundaryGap: false,<br>          axisLine: &#123;<br>            lineStyle: &#123;<br>              color: &#x27;#57617B&#x27;<br>            &#125;<br>          &#125;,<br>          data: [&#x27;13:00&#x27;, &#x27;13:05&#x27;, &#x27;13:10&#x27;, &#x27;13:15&#x27;, &#x27;13:20&#x27;, &#x27;13:25&#x27;, &#x27;13:30&#x27;, &#x27;13:35&#x27;, &#x27;13:40&#x27;, &#x27;13:45&#x27;, &#x27;13:50&#x27;, &#x27;13:55&#x27;]<br>        &#125;],<br>        yAxis: [&#123;<br>          type: &#x27;value&#x27;,<br>          name: &#x27;(%)&#x27;,<br>          axisTick: &#123;<br>            show: false<br>          &#125;,<br>          axisLine: &#123;<br>            lineStyle: &#123;<br>              color: &#x27;#57617B&#x27;<br>            &#125;<br>          &#125;,<br>          axisLabel: &#123;<br>            margin: 10,<br>            textStyle: &#123;<br>              fontSize: 14<br>            &#125;<br>          &#125;,<br>          splitLine: &#123;<br>            lineStyle: &#123;<br>              color: &#x27;#57617B&#x27;<br>            &#125;<br>          &#125;<br>        &#125;],<br>        series: [&#123;<br>          name: &#x27;CMCC&#x27;,<br>          type: &#x27;line&#x27;,<br>          smooth: true,<br>          symbol: &#x27;circle&#x27;,<br>          symbolSize: 5,<br>          showSymbol: false,<br>          lineStyle: &#123;<br>            normal: &#123;<br>              width: 1<br>            &#125;<br>          &#125;,<br>          areaStyle: &#123;<br>            normal: &#123;<br>              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [&#123;<br>                offset: 0,<br>                color: &#x27;rgba(137, 189, 27, 0.3)&#x27;<br>              &#125;, &#123;<br>                offset: 0.8,<br>                color: &#x27;rgba(137, 189, 27, 0)&#x27;<br>              &#125;], false),<br>              shadowColor: &#x27;rgba(0, 0, 0, 0.1)&#x27;,<br>              shadowBlur: 10<br>            &#125;<br>          &#125;,<br>          itemStyle: &#123;<br>            normal: &#123;<br>              color: &#x27;rgb(137,189,27)&#x27;,<br>              borderColor: &#x27;rgba(137,189,2,0.27)&#x27;,<br>              borderWidth: 12<br><br>            &#125;<br>          &#125;,<br>          data: [220, 182, 191, 134, 150, 120, 110, 125, 145, 122, 165, 122]<br>        &#125;, &#123;<br>          name: &#x27;CTCC&#x27;,<br>          type: &#x27;line&#x27;,<br>          smooth: true,<br>          symbol: &#x27;circle&#x27;,<br>          symbolSize: 5,<br>          showSymbol: false,<br>          lineStyle: &#123;<br>            normal: &#123;<br>              width: 1<br>            &#125;<br>          &#125;,<br>          areaStyle: &#123;<br>            normal: &#123;<br>              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [&#123;<br>                offset: 0,<br>                color: &#x27;rgba(0, 136, 212, 0.3)&#x27;<br>              &#125;, &#123;<br>                offset: 0.8,<br>                color: &#x27;rgba(0, 136, 212, 0)&#x27;<br>              &#125;], false),<br>              shadowColor: &#x27;rgba(0, 0, 0, 0.1)&#x27;,<br>              shadowBlur: 10<br>            &#125;<br>          &#125;,<br>          itemStyle: &#123;<br>            normal: &#123;<br>              color: &#x27;rgb(0,136,212)&#x27;,<br>              borderColor: &#x27;rgba(0,136,212,0.2)&#x27;,<br>              borderWidth: 12<br><br>            &#125;<br>          &#125;,<br>          data: [120, 110, 125, 145, 122, 165, 122, 220, 182, 191, 134, 150]<br>        &#125;, &#123;<br>          name: &#x27;CUCC&#x27;,<br>          type: &#x27;line&#x27;,<br>          smooth: true,<br>          symbol: &#x27;circle&#x27;,<br>          symbolSize: 5,<br>          showSymbol: false,<br>          lineStyle: &#123;<br>            normal: &#123;<br>              width: 1<br>            &#125;<br>          &#125;,<br>          areaStyle: &#123;<br>            normal: &#123;<br>              color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [&#123;<br>                offset: 0,<br>                color: &#x27;rgba(219, 50, 51, 0.3)&#x27;<br>              &#125;, &#123;<br>                offset: 0.8,<br>                color: &#x27;rgba(219, 50, 51, 0)&#x27;<br>              &#125;], false),<br>              shadowColor: &#x27;rgba(0, 0, 0, 0.1)&#x27;,<br>              shadowBlur: 10<br>            &#125;<br>          &#125;,<br>          itemStyle: &#123;<br>            normal: &#123;<br>              color: &#x27;rgb(219,50,51)&#x27;,<br>              borderColor: &#x27;rgba(219,50,51,0.2)&#x27;,<br>              borderWidth: 12<br>            &#125;<br>          &#125;,<br>          data: [220, 182, 125, 145, 122, 191, 134, 150, 120, 110, 165, 122]<br>        &#125;]<br>      &#125;)<br>    &#125;<br>  &#125;<br>&#125;<br>&lt;/script&gt;<br><br></code></pre></td></tr></table></figure>

<p>使用了一个js</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br></pre></td><td class="code"><pre><code class="hljs javascript"><span class="hljs-keyword">import</span> &#123; debounce &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;@/utils&#x27;</span><br><br><span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> &#123;<br>  <span class="hljs-title function_">data</span>(<span class="hljs-params"></span>) &#123;<br>    <span class="hljs-keyword">return</span> &#123;<br>      <span class="hljs-attr">$_sidebarElm</span>: <span class="hljs-literal">null</span>,<br>      <span class="hljs-attr">$_resizeHandler</span>: <span class="hljs-literal">null</span><br>    &#125;<br>  &#125;,<br>  <span class="hljs-title function_">mounted</span>(<span class="hljs-params"></span>) &#123;<br>    <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">initListener</span>()<br>  &#125;,<br>  <span class="hljs-title function_">activated</span>(<span class="hljs-params"></span>) &#123;<br>    <span class="hljs-keyword">if</span> (!<span class="hljs-variable language_">this</span>.<span class="hljs-property">$_resizeHandler</span>) &#123;<br>      <span class="hljs-comment">// avoid duplication init</span><br>      <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">initListener</span>()<br>    &#125;<br><br>    <span class="hljs-comment">// when keep-alive chart activated, auto resize</span><br>    <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">resize</span>()<br>  &#125;,<br>  <span class="hljs-title function_">beforeDestroy</span>(<span class="hljs-params"></span>) &#123;<br>    <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">destroyListener</span>()<br>  &#125;,<br>  <span class="hljs-title function_">deactivated</span>(<span class="hljs-params"></span>) &#123;<br>    <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">destroyListener</span>()<br>  &#125;,<br>  <span class="hljs-attr">methods</span>: &#123;<br>    <span class="hljs-comment">// use $_ for mixins properties</span><br>    <span class="hljs-comment">// https://vuejs.org/v2/style-guide/index.html#Private-property-names-essential</span><br>    $_sidebarResizeHandler(e) &#123;<br>      <span class="hljs-keyword">if</span> (e.<span class="hljs-property">propertyName</span> === <span class="hljs-string">&#x27;width&#x27;</span>) &#123;<br>        <span class="hljs-variable language_">this</span>.$_resizeHandler()<br>      &#125;<br>    &#125;,<br>    <span class="hljs-title function_">initListener</span>(<span class="hljs-params"></span>) &#123;<br>      <span class="hljs-variable language_">this</span>.<span class="hljs-property">$_resizeHandler</span> = <span class="hljs-title function_">debounce</span>(<span class="hljs-function">() =&gt;</span> &#123;<br>        <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">resize</span>()<br>      &#125;, <span class="hljs-number">100</span>)<br>      <span class="hljs-variable language_">window</span>.<span class="hljs-title function_">addEventListener</span>(<span class="hljs-string">&#x27;resize&#x27;</span>, <span class="hljs-variable language_">this</span>.<span class="hljs-property">$_resizeHandler</span>)<br><br>      <span class="hljs-variable language_">this</span>.<span class="hljs-property">$_sidebarElm</span> = <span class="hljs-variable language_">document</span>.<span class="hljs-title function_">getElementsByClassName</span>(<span class="hljs-string">&#x27;sidebar-container&#x27;</span>)[<span class="hljs-number">0</span>]<br>      <span class="hljs-variable language_">this</span>.<span class="hljs-property">$_sidebarElm</span> &amp;&amp; <span class="hljs-variable language_">this</span>.<span class="hljs-property">$_sidebarElm</span>.<span class="hljs-title function_">addEventListener</span>(<span class="hljs-string">&#x27;transitionend&#x27;</span>, <span class="hljs-variable language_">this</span>.<span class="hljs-property">$_sidebarResizeHandler</span>)<br>    &#125;,<br>    <span class="hljs-title function_">destroyListener</span>(<span class="hljs-params"></span>) &#123;<br>      <span class="hljs-variable language_">window</span>.<span class="hljs-title function_">removeEventListener</span>(<span class="hljs-string">&#x27;resize&#x27;</span>, <span class="hljs-variable language_">this</span>.<span class="hljs-property">$_resizeHandler</span>)<br>      <span class="hljs-variable language_">this</span>.<span class="hljs-property">$_resizeHandler</span> = <span class="hljs-literal">null</span><br><br>      <span class="hljs-variable language_">this</span>.<span class="hljs-property">$_sidebarElm</span> &amp;&amp; <span class="hljs-variable language_">this</span>.<span class="hljs-property">$_sidebarElm</span>.<span class="hljs-title function_">removeEventListener</span>(<span class="hljs-string">&#x27;transitionend&#x27;</span>, <span class="hljs-variable language_">this</span>.<span class="hljs-property">$_sidebarResizeHandler</span>)<br>    &#125;,<br>    <span class="hljs-title function_">resize</span>(<span class="hljs-params"></span>) &#123;<br>      <span class="hljs-keyword">const</span> &#123; chart &#125; = <span class="hljs-variable language_">this</span><br>      chart &amp;&amp; chart.<span class="hljs-title function_">resize</span>()<br>    &#125;<br>  &#125;<br>&#125;<br><br></code></pre></td></tr></table></figure>

<p>有调用到一个方法</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><code class="hljs javascript"><span class="hljs-keyword">export</span> <span class="hljs-keyword">function</span> <span class="hljs-title function_">debounce</span>(<span class="hljs-params">func, wait, immediate</span>) &#123;<br>  <span class="hljs-keyword">let</span> timeout, args, context, timestamp, result<br><br>  <span class="hljs-keyword">const</span> later = <span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) &#123;<br>    <span class="hljs-comment">// 据上一次触发时间间隔</span><br>    <span class="hljs-keyword">const</span> last = +<span class="hljs-keyword">new</span> <span class="hljs-title class_">Date</span>() - timestamp<br><br>    <span class="hljs-comment">// 上次被包装函数被调用时间间隔 last 小于设定时间间隔 wait</span><br>    <span class="hljs-keyword">if</span> (last &lt; wait &amp;&amp; last &gt; <span class="hljs-number">0</span>) &#123;<br>      timeout = <span class="hljs-built_in">setTimeout</span>(later, wait - last)<br>    &#125; <span class="hljs-keyword">else</span> &#123;<br>      timeout = <span class="hljs-literal">null</span><br>      <span class="hljs-comment">// 如果设定为immediate===true，因为开始边界已经调用过了此处无需调用</span><br>      <span class="hljs-keyword">if</span> (!immediate) &#123;<br>        result = func.<span class="hljs-title function_">apply</span>(context, args)<br>        <span class="hljs-keyword">if</span> (!timeout) context = args = <span class="hljs-literal">null</span><br>      &#125;<br>    &#125;<br>  &#125;<br><br>  <span class="hljs-keyword">return</span> <span class="hljs-keyword">function</span>(<span class="hljs-params">...args</span>) &#123;<br>    context = <span class="hljs-variable language_">this</span><br>    timestamp = +<span class="hljs-keyword">new</span> <span class="hljs-title class_">Date</span>()<br>    <span class="hljs-keyword">const</span> callNow = immediate &amp;&amp; !timeout<br>    <span class="hljs-comment">// 如果延时不存在，重新设定延时</span><br>    <span class="hljs-keyword">if</span> (!timeout) timeout = <span class="hljs-built_in">setTimeout</span>(later, wait)<br>    <span class="hljs-keyword">if</span> (callNow) &#123;<br>      result = func.<span class="hljs-title function_">apply</span>(context, args)<br>      context = args = <span class="hljs-literal">null</span><br>    &#125;<br><br>    <span class="hljs-keyword">return</span> result<br>  &#125;<br>&#125;<br></code></pre></td></tr></table></figure>

<p> 上述代码 来自于开源框架 vue-element-admin</p>
<h3 id="一个偷懒"><a href="#一个偷懒" class="headerlink" title="一个偷懒"></a>一个偷懒</h3><p>有一题是</p>
<blockquote>
<p>数据列表上方点击[导出]按钮后应将数据列表内容导出“.csv”文件，但现在导出格式为“.xlsx”，</p>
</blockquote>
<p>我偷懒的 直接修改了 前端下载的后缀文件名 这很明显是不合理的</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><code class="hljs javascript"><span class="hljs-title function_">handleExport</span>(<span class="hljs-params"></span>) &#123;<br>  <span class="hljs-variable language_">this</span>.<span class="hljs-title function_">download</span>(<span class="hljs-string">&#x27;system/SchoolSubjectManage/export&#x27;</span>, &#123;<br>    ...<span class="hljs-variable language_">this</span>.<span class="hljs-property">queryParams</span><br>  &#125;, <span class="hljs-string">`SchoolSubjectManage_<span class="hljs-subst">$&#123;<span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>().getTime()&#125;</span>.csv`</span>)<br>&#125;<br></code></pre></td></tr></table></figure>

<p>是的直接修改后缀名</p>
<p>还好office支持强行读取… 糊弄过去比赛了</p>
<p> 不过还是要思考一下如何解决这个问题</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-meta">@PreAuthorize(&quot;@ss.hasPermi(&#x27;system:manage:export&#x27;)&quot;)</span><br><span class="hljs-meta">@Log(title = &quot;学科分类管理&quot;, businessType = BusinessType.EXPORT)</span><br><span class="hljs-meta">@PostMapping(&quot;/export&quot;)</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">export</span><span class="hljs-params">(HttpServletResponse response, SchoolSubjectManage schoolSubjectManage)</span><br>&#123;<br>    List&lt;SchoolSubjectManage&gt; list = schoolSubjectManageService.selectSchoolSubjectManageList(schoolSubjectManage);<br>    ExcelUtil&lt;SchoolSubjectManage&gt; util = <span class="hljs-keyword">new</span> <span class="hljs-title class_">ExcelUtil</span>&lt;SchoolSubjectManage&gt;(SchoolSubjectManage.class);<br>    util.exportExcel(response, list, <span class="hljs-string">&quot;学科分类管理数据&quot;</span>);<br>&#125;<br></code></pre></td></tr></table></figure>

<p>这是请求层代码 可以看到调用了一个 ExcelUtil 的泛型…</p>
<p>但是他的实现类非常复杂…</p>
<p>我这里引用 一段别的博客提供的代码 也很复杂 比赛中根本来不及实现</p>
<p>但是可以作为知识积累</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br><span class="line">308</span><br><span class="line">309</span><br><span class="line">310</span><br><span class="line">311</span><br><span class="line">312</span><br><span class="line">313</span><br><span class="line">314</span><br><span class="line">315</span><br><span class="line">316</span><br><span class="line">317</span><br><span class="line">318</span><br><span class="line">319</span><br><span class="line">320</span><br><span class="line">321</span><br><span class="line">322</span><br><span class="line">323</span><br><span class="line">324</span><br><span class="line">325</span><br><span class="line">326</span><br><span class="line">327</span><br><span class="line">328</span><br><span class="line">329</span><br><span class="line">330</span><br><span class="line">331</span><br><span class="line">332</span><br><span class="line">333</span><br><span class="line">334</span><br><span class="line">335</span><br><span class="line">336</span><br><span class="line">337</span><br><span class="line">338</span><br><span class="line">339</span><br><span class="line">340</span><br><span class="line">341</span><br><span class="line">342</span><br><span class="line">343</span><br><span class="line">344</span><br><span class="line">345</span><br><span class="line">346</span><br><span class="line">347</span><br><span class="line">348</span><br><span class="line">349</span><br><span class="line">350</span><br><span class="line">351</span><br><span class="line">352</span><br><span class="line">353</span><br><span class="line">354</span><br><span class="line">355</span><br><span class="line">356</span><br><span class="line">357</span><br><span class="line">358</span><br><span class="line">359</span><br><span class="line">360</span><br><span class="line">361</span><br><span class="line">362</span><br><span class="line">363</span><br><span class="line">364</span><br><span class="line">365</span><br><span class="line">366</span><br><span class="line">367</span><br><span class="line">368</span><br><span class="line">369</span><br><span class="line">370</span><br><span class="line">371</span><br><span class="line">372</span><br><span class="line">373</span><br><span class="line">374</span><br><span class="line">375</span><br><span class="line">376</span><br><span class="line">377</span><br><span class="line">378</span><br><span class="line">379</span><br><span class="line">380</span><br><span class="line">381</span><br><span class="line">382</span><br><span class="line">383</span><br><span class="line">384</span><br><span class="line">385</span><br><span class="line">386</span><br><span class="line">387</span><br><span class="line">388</span><br><span class="line">389</span><br><span class="line">390</span><br><span class="line">391</span><br><span class="line">392</span><br><span class="line">393</span><br><span class="line">394</span><br><span class="line">395</span><br><span class="line">396</span><br><span class="line">397</span><br><span class="line">398</span><br><span class="line">399</span><br><span class="line">400</span><br><span class="line">401</span><br><span class="line">402</span><br><span class="line">403</span><br><span class="line">404</span><br><span class="line">405</span><br><span class="line">406</span><br><span class="line">407</span><br><span class="line">408</span><br><span class="line">409</span><br><span class="line">410</span><br><span class="line">411</span><br><span class="line">412</span><br><span class="line">413</span><br><span class="line">414</span><br><span class="line">415</span><br><span class="line">416</span><br><span class="line">417</span><br><span class="line">418</span><br><span class="line">419</span><br><span class="line">420</span><br><span class="line">421</span><br><span class="line">422</span><br><span class="line">423</span><br><span class="line">424</span><br><span class="line">425</span><br><span class="line">426</span><br><span class="line">427</span><br><span class="line">428</span><br><span class="line">429</span><br><span class="line">430</span><br><span class="line">431</span><br><span class="line">432</span><br><span class="line">433</span><br><span class="line">434</span><br><span class="line">435</span><br><span class="line">436</span><br><span class="line">437</span><br><span class="line">438</span><br><span class="line">439</span><br><span class="line">440</span><br><span class="line">441</span><br><span class="line">442</span><br><span class="line">443</span><br><span class="line">444</span><br><span class="line">445</span><br><span class="line">446</span><br><span class="line">447</span><br><span class="line">448</span><br><span class="line">449</span><br><span class="line">450</span><br><span class="line">451</span><br><span class="line">452</span><br><span class="line">453</span><br><span class="line">454</span><br><span class="line">455</span><br><span class="line">456</span><br><span class="line">457</span><br><span class="line">458</span><br><span class="line">459</span><br><span class="line">460</span><br><span class="line">461</span><br><span class="line">462</span><br><span class="line">463</span><br><span class="line">464</span><br><span class="line">465</span><br><span class="line">466</span><br><span class="line">467</span><br><span class="line">468</span><br><span class="line">469</span><br><span class="line">470</span><br><span class="line">471</span><br><span class="line">472</span><br></pre></td><td class="code"><pre><code class="hljs java"><span class="hljs-keyword">package</span> com.ruoyi.common.utils.poi;<br> <br><span class="hljs-keyword">import</span> com.alibaba.fastjson.JSONArray;<br><span class="hljs-keyword">import</span> com.alibaba.fastjson.JSONObject;<br><span class="hljs-keyword">import</span> com.ruoyi.common.utils.StringUtils;<br><span class="hljs-keyword">import</span> org.apache.commons.collections.CollectionUtils;<br><span class="hljs-keyword">import</span> org.springframework.web.multipart.MultipartFile;<br> <br><span class="hljs-keyword">import</span> javax.servlet.http.HttpServletResponse;<br><span class="hljs-keyword">import</span> java.io.*;<br><span class="hljs-keyword">import</span> java.net.URLEncoder;<br><span class="hljs-keyword">import</span> java.util.*;<br><span class="hljs-comment">/*</span><br><span class="hljs-comment">* 解析csv文件的输入流工具类</span><br><span class="hljs-comment">* */</span><br><span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">CSVUtils</span> &#123;<br>    <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">static</span> <span class="hljs-type">String</span> <span class="hljs-variable">CSV_LOWER</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;csv&quot;</span>;<br>    <span class="hljs-keyword">private</span> <span class="hljs-keyword">final</span> <span class="hljs-keyword">static</span> <span class="hljs-type">String</span> <span class="hljs-variable">CSV</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;CSV&quot;</span>;<br> <br>    <span class="hljs-comment">/**</span><br><span class="hljs-comment">     * 功能说明：获取UTF-8编码文本文件开头的BOM签名。</span><br><span class="hljs-comment">     * BOM(Byte Order Mark)，是UTF编码方案里用于标识编码的标准标记。例：接收者收到以EF BB BF开头的字节流，就知道是UTF-8编码。</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@return</span> UTF-8编码文本文件开头的BOM签名</span><br><span class="hljs-comment">     */</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> String <span class="hljs-title function_">getBom</span><span class="hljs-params">()</span> &#123;<br> <br>        <span class="hljs-type">byte</span>[] b = &#123;(<span class="hljs-type">byte</span>)<span class="hljs-number">0xEF</span>, (<span class="hljs-type">byte</span>)<span class="hljs-number">0xBB</span>, (<span class="hljs-type">byte</span>)<span class="hljs-number">0xBF</span>&#125;;<br>        <span class="hljs-keyword">return</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">String</span>(b);<br>    &#125;<br> <br>    <span class="hljs-comment">/**</span><br><span class="hljs-comment">     * 生成CVS文件</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> exportData</span><br><span class="hljs-comment">     *       源数据List</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> map</span><br><span class="hljs-comment">     *       csv文件的列表头map</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> outPutPath</span><br><span class="hljs-comment">     *       文件路径</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> fileName</span><br><span class="hljs-comment">     *       文件名称</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@return</span></span><br><span class="hljs-comment">     */</span><br>    <span class="hljs-meta">@SuppressWarnings(&quot;rawtypes&quot;)</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> File <span class="hljs-title function_">createCsvFile</span><span class="hljs-params">(List exportData, LinkedHashMap map, String outPutPath,</span><br><span class="hljs-params">                                     String fileName)</span> &#123;<br>        <span class="hljs-type">File</span> <span class="hljs-variable">csvFile</span> <span class="hljs-operator">=</span> <span class="hljs-literal">null</span>;<br>        <span class="hljs-type">BufferedWriter</span> <span class="hljs-variable">csvFileOutputStream</span> <span class="hljs-operator">=</span> <span class="hljs-literal">null</span>;<br>        <span class="hljs-keyword">try</span> &#123;<br>            <span class="hljs-type">File</span> <span class="hljs-variable">file</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">File</span>(outPutPath);<br>            <span class="hljs-keyword">if</span> (!file.exists()) &#123;<br>                file.mkdirs();<br>            &#125;<br>            <span class="hljs-comment">//定义文件名格式并创建</span><br>            <span class="hljs-type">String</span> <span class="hljs-variable">fileOpath</span> <span class="hljs-operator">=</span> outPutPath + File.separator + fileName+<span class="hljs-string">&quot;.csv&quot;</span>;<br>            csvFile =<span class="hljs-keyword">new</span> <span class="hljs-title class_">File</span>(fileOpath);<br>            file.createNewFile();<br>            <span class="hljs-comment">// UTF-8使正确读取分隔符&quot;,&quot;</span><br>            <span class="hljs-comment">//如果生产文件乱码，windows下用gbk，linux用UTF-8</span><br>            csvFileOutputStream = <span class="hljs-keyword">new</span> <span class="hljs-title class_">BufferedWriter</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">OutputStreamWriter</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">FileOutputStream</span>(<br>                    csvFile), <span class="hljs-string">&quot;UTF-8&quot;</span>), <span class="hljs-number">1024</span>);<br> <br>            <span class="hljs-comment">//写入前段字节流，防止乱码</span><br>            csvFileOutputStream.write(getBom());<br>            <span class="hljs-comment">// 写入文件头部</span><br>            <span class="hljs-keyword">for</span> (<span class="hljs-type">Iterator</span> <span class="hljs-variable">propertyIterator</span> <span class="hljs-operator">=</span> map.entrySet().iterator(); propertyIterator.hasNext();) &#123;<br>                java.util.Map.<span class="hljs-type">Entry</span> <span class="hljs-variable">propertyEntry</span> <span class="hljs-operator">=</span> (java.util.Map.Entry) propertyIterator.next();<br>                csvFileOutputStream.write((String) propertyEntry.getValue() != <span class="hljs-literal">null</span> ? (String) propertyEntry.getValue() : <span class="hljs-string">&quot;&quot;</span> );<br>                <span class="hljs-keyword">if</span> (propertyIterator.hasNext()) &#123;<br>                    csvFileOutputStream.write(<span class="hljs-string">&quot;,&quot;</span>);<br>                &#125;<br>            &#125;<br>            csvFileOutputStream.newLine();<br>            <span class="hljs-comment">// 写入文件内容</span><br>            <span class="hljs-keyword">for</span> (<span class="hljs-type">Iterator</span> <span class="hljs-variable">iterator</span> <span class="hljs-operator">=</span> exportData.iterator(); iterator.hasNext();) &#123;<br>                <span class="hljs-type">Object</span> <span class="hljs-variable">row</span> <span class="hljs-operator">=</span> (Object) iterator.next();<br>                <span class="hljs-keyword">for</span> (<span class="hljs-type">Iterator</span> <span class="hljs-variable">propertyIterator</span> <span class="hljs-operator">=</span> map.entrySet().iterator(); propertyIterator<br>                        .hasNext();) &#123;<br>                    java.util.Map.<span class="hljs-type">Entry</span> <span class="hljs-variable">propertyEntry</span> <span class="hljs-operator">=</span> (java.util.Map.Entry) propertyIterator<br>                            .next();<br>                    <span class="hljs-type">String</span> <span class="hljs-variable">str</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;&quot;</span>;<br>                    <span class="hljs-keyword">if</span>(row !=<span class="hljs-literal">null</span> &amp;&amp; !<span class="hljs-string">&quot;&quot;</span>.equals( propertyEntry.getKey()) &amp;&amp; <span class="hljs-literal">null</span> != propertyEntry.getKey() &amp;&amp; ((Map)row).get(propertyEntry.getKey()) != <span class="hljs-literal">null</span>)&#123;<br>                        str=((Map)row).get(propertyEntry.getKey()).toString();<br> <br>                    &#125;<br>                    <span class="hljs-keyword">if</span>(StringUtils.isEmpty(str))&#123;<br>                        str=<span class="hljs-string">&quot;&quot;</span>;<br>                    &#125;<span class="hljs-keyword">else</span>&#123;<br>                        <span class="hljs-keyword">if</span>(str.indexOf(<span class="hljs-string">&quot;,&quot;</span>)&gt;=<span class="hljs-number">0</span>)&#123;<br>                            str=<span class="hljs-string">&quot;\&quot;&quot;</span>+str+<span class="hljs-string">&quot;\&quot;&quot;</span>;<br>                        &#125;<br>                    &#125;<br>                    csvFileOutputStream.write(str);<br>                    <span class="hljs-keyword">if</span> (propertyIterator.hasNext()) &#123;<br>                        csvFileOutputStream.write(<span class="hljs-string">&quot;,&quot;</span>);<br>                    &#125;<br>                &#125;<br>                <span class="hljs-keyword">if</span> (iterator.hasNext()) &#123;<br>                    csvFileOutputStream.newLine();<br>                &#125;<br>            &#125;<br>            csvFileOutputStream.flush();<br>        &#125; <span class="hljs-keyword">catch</span> (Exception e) &#123;<br>            <span class="hljs-comment">//log.error(&quot;error：&#123;&#125;&quot;, e);</span><br>        &#125; <span class="hljs-keyword">finally</span> &#123;<br>            <span class="hljs-keyword">try</span> &#123;<br>                csvFileOutputStream.close();<br>            &#125; <span class="hljs-keyword">catch</span> (IOException e) &#123;<br>               <span class="hljs-comment">// log.error(&quot;error：&#123;&#125;&quot;, e);</span><br>            &#125;<br>        &#125;<br>        <span class="hljs-keyword">return</span> csvFile;<br>    &#125;<br> <br>    <span class="hljs-comment">/**</span><br><span class="hljs-comment">     *     生成并下载csv文件</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> response</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> exportData</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> map</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> outPutPath</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> fileName</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@throws</span> IOException</span><br><span class="hljs-comment">     */</span><br>    <span class="hljs-meta">@SuppressWarnings(&quot;rawtypes&quot;)</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">exportDataFile</span><span class="hljs-params">(HttpServletResponse response, List exportData, LinkedHashMap map, String outPutPath, String fileName)</span> <span class="hljs-keyword">throws</span> IOException&#123;<br>        <span class="hljs-type">File</span> <span class="hljs-variable">csvFile</span> <span class="hljs-operator">=</span> <span class="hljs-literal">null</span>;<br>        <span class="hljs-type">BufferedWriter</span> <span class="hljs-variable">csvFileOutputStream</span> <span class="hljs-operator">=</span> <span class="hljs-literal">null</span>;<br>        <span class="hljs-keyword">try</span> &#123;<br>            <span class="hljs-type">File</span> <span class="hljs-variable">file</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">File</span>(outPutPath);<br>            <span class="hljs-keyword">if</span> (!file.exists()) &#123;<br>                file.mkdirs();<br>            &#125;<br>            <span class="hljs-comment">//定义文件名格式并创建</span><br>            csvFile =<span class="hljs-keyword">new</span> <span class="hljs-title class_">File</span>(outPutPath+fileName+<span class="hljs-string">&quot;.csv&quot;</span>);<br>            <span class="hljs-keyword">if</span>(csvFile.exists())&#123;<br>                csvFile.delete();<br>            &#125;<br>            csvFile.createNewFile();<br>            <span class="hljs-comment">// UTF-8使正确读取分隔符&quot;,&quot;</span><br>            <span class="hljs-comment">//如果生产文件乱码，windows下用gbk，linux用UTF-8</span><br>            csvFileOutputStream = <span class="hljs-keyword">new</span> <span class="hljs-title class_">BufferedWriter</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">OutputStreamWriter</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">FileOutputStream</span>(csvFile), <span class="hljs-string">&quot;UTF-8&quot;</span>), <span class="hljs-number">1024</span>);<br>            <span class="hljs-comment">//写入前段字节流，防止乱码</span><br>            csvFileOutputStream.write(getBom());<br>            <span class="hljs-comment">// 写入文件头部</span><br>            <span class="hljs-keyword">for</span> (<span class="hljs-type">Iterator</span> <span class="hljs-variable">propertyIterator</span> <span class="hljs-operator">=</span> map.entrySet().iterator(); propertyIterator.hasNext();) &#123;<br>                java.util.Map.<span class="hljs-type">Entry</span> <span class="hljs-variable">propertyEntry</span> <span class="hljs-operator">=</span> (java.util.Map.Entry) propertyIterator.next();<br>                csvFileOutputStream.write((String) propertyEntry.getValue() != <span class="hljs-literal">null</span> ? (String) propertyEntry.getValue() : <span class="hljs-string">&quot;&quot;</span> );<br>                <span class="hljs-keyword">if</span> (propertyIterator.hasNext()) &#123;<br>                    csvFileOutputStream.write(<span class="hljs-string">&quot;,&quot;</span>);<br>                &#125;<br>            &#125;<br>            csvFileOutputStream.newLine();<br>            <span class="hljs-keyword">if</span>(CollectionUtils.isNotEmpty(exportData)) &#123;<br>                <span class="hljs-comment">// 写入文件内容</span><br>                <span class="hljs-keyword">for</span> (<span class="hljs-type">Iterator</span> <span class="hljs-variable">iterator</span> <span class="hljs-operator">=</span> exportData.iterator(); iterator.hasNext(); ) &#123;<br>                    <span class="hljs-type">Object</span> <span class="hljs-variable">row</span> <span class="hljs-operator">=</span> (Object) iterator.next();<br>                    <span class="hljs-keyword">for</span> (<span class="hljs-type">Iterator</span> <span class="hljs-variable">propertyIterator</span> <span class="hljs-operator">=</span> map.entrySet().iterator(); propertyIterator<br>                            .hasNext(); ) &#123;<br>                        java.util.Map.<span class="hljs-type">Entry</span> <span class="hljs-variable">propertyEntry</span> <span class="hljs-operator">=</span> (java.util.Map.Entry) propertyIterator<br>                                .next();<br>                        <span class="hljs-type">String</span> <span class="hljs-variable">str</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;&quot;</span>;<br>                        <span class="hljs-keyword">if</span> (row != <span class="hljs-literal">null</span> &amp;&amp; !<span class="hljs-string">&quot;&quot;</span>.equals(propertyEntry.getKey()) &amp;&amp; <span class="hljs-literal">null</span> != propertyEntry.getKey() &amp;&amp; ((Map) row).get(propertyEntry.getKey()) != <span class="hljs-literal">null</span>) &#123;<br>                            str = ((Map) row).get(propertyEntry.getKey()).toString();<br> <br>                        &#125;<br>                        <span class="hljs-keyword">if</span> (StringUtils.isEmpty(str)) &#123;<br>                            str = <span class="hljs-string">&quot;&quot;</span>;<br>                        &#125; <span class="hljs-keyword">else</span> &#123;<br>                            <span class="hljs-keyword">if</span> (str.indexOf(<span class="hljs-string">&quot;,&quot;</span>) &gt;= <span class="hljs-number">0</span>) &#123;<br>                                str = <span class="hljs-string">&quot;\&quot;&quot;</span> + str + <span class="hljs-string">&quot;\&quot;&quot;</span>;<br>                            &#125;<br>                        &#125;<br>                        csvFileOutputStream.write(str);<br>                        <span class="hljs-keyword">if</span> (propertyIterator.hasNext()) &#123;<br>                            csvFileOutputStream.write(<span class="hljs-string">&quot;,&quot;</span>);<br>                        &#125;<br>                    &#125;<br>                    <span class="hljs-keyword">if</span> (iterator.hasNext()) &#123;<br>                        csvFileOutputStream.newLine();<br>                    &#125;<br>                &#125;<br>            &#125;<br>            csvFileOutputStream.flush();<br>        &#125; <span class="hljs-keyword">catch</span> (Exception e) &#123;<br>            <span class="hljs-comment">//log.error(&quot;error：&#123;&#125;&quot;, e);</span><br>        &#125; <span class="hljs-keyword">finally</span> &#123;<br>            <span class="hljs-keyword">try</span> &#123;<br>                csvFileOutputStream.close();<br>            &#125; <span class="hljs-keyword">catch</span> (IOException e) &#123;<br>                <span class="hljs-comment">//log.error(&quot;error：&#123;&#125;&quot;, e);</span><br>            &#125;<br>        &#125;<br>        downFile(response,outPutPath,fileName);<br>        csvFile.delete();<br>    &#125;<br> <br>    <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">downFile</span><span class="hljs-params">(HttpServletResponse response, String outPutPath, String fileName)</span><span class="hljs-keyword">throws</span> IOException&#123;<br>        <span class="hljs-type">InputStream</span> <span class="hljs-variable">in</span> <span class="hljs-operator">=</span> <span class="hljs-literal">null</span>;<br>        <span class="hljs-keyword">try</span> &#123;<br>            in = <span class="hljs-keyword">new</span> <span class="hljs-title class_">FileInputStream</span>(outPutPath+fileName+<span class="hljs-string">&quot;.csv&quot;</span>);<br>            <span class="hljs-type">int</span> <span class="hljs-variable">len</span> <span class="hljs-operator">=</span> <span class="hljs-number">0</span>;<br>            <span class="hljs-type">byte</span>[] buffer = <span class="hljs-keyword">new</span> <span class="hljs-title class_">byte</span>[<span class="hljs-number">1024</span>];<br> <br>            <span class="hljs-type">OutputStream</span> <span class="hljs-variable">out</span> <span class="hljs-operator">=</span> response.getOutputStream();<br>            response.setContentType(<span class="hljs-string">&quot;application/csv;charset=UTF-8&quot;</span>);<br>            response.setHeader(<span class="hljs-string">&quot;Content-Disposition&quot;</span>,<span class="hljs-string">&quot;attachment; filename=&quot;</span> + URLEncoder.encode(fileName+<span class="hljs-string">&quot;.csv&quot;</span>, <span class="hljs-string">&quot;UTF-8&quot;</span>));<br>            response.setCharacterEncoding(<span class="hljs-string">&quot;UTF-8&quot;</span>);<br>            <span class="hljs-keyword">while</span> ((len = in.read(buffer)) &gt; <span class="hljs-number">0</span>) &#123;<br>                out.write(<span class="hljs-keyword">new</span> <span class="hljs-title class_">byte</span>[] &#123; (<span class="hljs-type">byte</span>) <span class="hljs-number">0xEF</span>, (<span class="hljs-type">byte</span>) <span class="hljs-number">0xBB</span>, (<span class="hljs-type">byte</span>) <span class="hljs-number">0xBF</span> &#125;);<br>                out.write(buffer, <span class="hljs-number">0</span>, len);<br>            &#125;<br>            out.close();<br>        &#125; <span class="hljs-keyword">catch</span> (FileNotFoundException e) &#123;<br>            <span class="hljs-comment">//log.error(&quot;error：&#123;&#125;&quot;, e);</span><br>        &#125; <span class="hljs-keyword">finally</span> &#123;<br>            <span class="hljs-keyword">if</span> (in != <span class="hljs-literal">null</span>) &#123;<br>                <span class="hljs-keyword">try</span> &#123;<br>                    in.close();<br>                &#125; <span class="hljs-keyword">catch</span> (Exception e) &#123;<br>                    <span class="hljs-comment">//log.error(&quot;error：&#123;&#125;&quot;, e);</span><br>                &#125;<br>            &#125;<br>        &#125;<br>    &#125;<br> <br>    <span class="hljs-comment">/**</span><br><span class="hljs-comment">     *     生成并csv文件</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> response</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> exportData</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> map</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> outPutPath</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> fileName</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@throws</span> IOException</span><br><span class="hljs-comment">     */</span><br>    <span class="hljs-meta">@SuppressWarnings(&quot;rawtypes&quot;)</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">exportFile</span><span class="hljs-params">(HttpServletResponse response, List exportData, LinkedHashMap map, String outPutPath, String fileName)</span> <span class="hljs-keyword">throws</span> IOException&#123;<br>        <span class="hljs-type">File</span> <span class="hljs-variable">csvFile</span> <span class="hljs-operator">=</span> <span class="hljs-literal">null</span>;<br>        <span class="hljs-type">BufferedWriter</span> <span class="hljs-variable">csvFileOutputStream</span> <span class="hljs-operator">=</span> <span class="hljs-literal">null</span>;<br>        <span class="hljs-keyword">try</span> &#123;<br>            <span class="hljs-type">File</span> <span class="hljs-variable">file</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">File</span>(outPutPath);<br>            <span class="hljs-keyword">if</span> (!file.exists()) &#123;<br>                file.mkdirs();<br>            &#125;<br>            <span class="hljs-comment">//定义文件名格式并创建</span><br>            csvFile =<span class="hljs-keyword">new</span> <span class="hljs-title class_">File</span>(outPutPath+fileName+<span class="hljs-string">&quot;.csv&quot;</span>);<br>            <span class="hljs-keyword">if</span>(csvFile.exists())&#123;<br>                csvFile.delete();<br>            &#125;<br>            csvFile.createNewFile();<br>            <span class="hljs-comment">// UTF-8使正确读取分隔符&quot;,&quot;</span><br>            <span class="hljs-comment">//如果生产文件乱码，windows下用gbk，linux用UTF-8</span><br>            csvFileOutputStream = <span class="hljs-keyword">new</span> <span class="hljs-title class_">BufferedWriter</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">OutputStreamWriter</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">FileOutputStream</span>(csvFile), <span class="hljs-string">&quot;UTF-8&quot;</span>), <span class="hljs-number">1024</span>);<br>            <span class="hljs-comment">//写入前段字节流，防止乱码</span><br>            csvFileOutputStream.write(getBom());<br>            <span class="hljs-comment">// 写入文件头部</span><br>            <span class="hljs-keyword">for</span> (<span class="hljs-type">Iterator</span> <span class="hljs-variable">propertyIterator</span> <span class="hljs-operator">=</span> map.entrySet().iterator(); propertyIterator.hasNext();) &#123;<br>                java.util.Map.<span class="hljs-type">Entry</span> <span class="hljs-variable">propertyEntry</span> <span class="hljs-operator">=</span> (java.util.Map.Entry) propertyIterator.next();<br>                csvFileOutputStream.write((String) propertyEntry.getValue() != <span class="hljs-literal">null</span> ? (String) propertyEntry.getValue() : <span class="hljs-string">&quot;&quot;</span> );<br>                <span class="hljs-keyword">if</span> (propertyIterator.hasNext()) &#123;<br>                    csvFileOutputStream.write(<span class="hljs-string">&quot;,&quot;</span>);<br>                &#125;<br>            &#125;<br>            csvFileOutputStream.newLine();<br>            <span class="hljs-keyword">if</span>(CollectionUtils.isNotEmpty(exportData)) &#123;<br>                <span class="hljs-comment">// 写入文件内容</span><br>                <span class="hljs-keyword">for</span> (<span class="hljs-type">Iterator</span> <span class="hljs-variable">iterator</span> <span class="hljs-operator">=</span> exportData.iterator(); iterator.hasNext(); ) &#123;<br>                    <span class="hljs-type">Object</span> <span class="hljs-variable">row</span> <span class="hljs-operator">=</span> (Object) iterator.next();<br>                    <span class="hljs-keyword">for</span> (<span class="hljs-type">Iterator</span> <span class="hljs-variable">propertyIterator</span> <span class="hljs-operator">=</span> map.entrySet().iterator(); propertyIterator<br>                            .hasNext(); ) &#123;<br>                        java.util.Map.<span class="hljs-type">Entry</span> <span class="hljs-variable">propertyEntry</span> <span class="hljs-operator">=</span> (java.util.Map.Entry) propertyIterator<br>                                .next();<br>                        <span class="hljs-type">String</span> <span class="hljs-variable">str</span> <span class="hljs-operator">=</span> <span class="hljs-string">&quot;&quot;</span>;<br>                        <span class="hljs-keyword">if</span> (row != <span class="hljs-literal">null</span> &amp;&amp; !<span class="hljs-string">&quot;&quot;</span>.equals(propertyEntry.getKey()) &amp;&amp; <span class="hljs-literal">null</span> != propertyEntry.getKey() &amp;&amp; ((Map) row).get(propertyEntry.getKey()) != <span class="hljs-literal">null</span>) &#123;<br>                            str = ((Map) row).get(propertyEntry.getKey()).toString();<br> <br>                        &#125;<br>                        <span class="hljs-keyword">if</span> (StringUtils.isEmpty(str)) &#123;<br>                            str = <span class="hljs-string">&quot;&quot;</span>;<br>                        &#125; <span class="hljs-keyword">else</span> &#123;<br>                            <span class="hljs-keyword">if</span> (str.indexOf(<span class="hljs-string">&quot;,&quot;</span>) &gt;= <span class="hljs-number">0</span>) &#123;<br>                                str = <span class="hljs-string">&quot;\&quot;&quot;</span> + str + <span class="hljs-string">&quot;\&quot;&quot;</span>;<br>                            &#125;<br>                        &#125;<br>                        csvFileOutputStream.write(str);<br>                        <span class="hljs-keyword">if</span> (propertyIterator.hasNext()) &#123;<br>                            csvFileOutputStream.write(<span class="hljs-string">&quot;,&quot;</span>);<br>                        &#125;<br>                    &#125;<br>                    <span class="hljs-keyword">if</span> (iterator.hasNext()) &#123;<br>                        csvFileOutputStream.newLine();<br>                    &#125;<br>                &#125;<br>            &#125;<br>            csvFileOutputStream.flush();<br>        &#125; <span class="hljs-keyword">catch</span> (Exception e) &#123;<br>            <span class="hljs-comment">//log.error(&quot;error：&#123;&#125;&quot;, e);</span><br>        &#125; <span class="hljs-keyword">finally</span> &#123;<br>            <span class="hljs-keyword">try</span> &#123;<br>                csvFileOutputStream.close();<br>            &#125; <span class="hljs-keyword">catch</span> (IOException e) &#123;<br>                <span class="hljs-comment">//log.error(&quot;error：&#123;&#125;&quot;, e);</span><br>            &#125;<br>        &#125;<br>    &#125;<br> <br> <br> <br> <br> <br>    <span class="hljs-comment">/**</span><br><span class="hljs-comment">     *     解析csv</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> response</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> exportData</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> map</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> outPutPath</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> fileName</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@throws</span> IOException</span><br><span class="hljs-comment">     */</span><br>    <span class="hljs-meta">@SuppressWarnings(&quot;rawtypes&quot;)</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">analysisExportFile</span><span class="hljs-params">(HttpServletResponse response, List exportData, LinkedHashMap map, String outPutPath, String fileName)</span> <span class="hljs-keyword">throws</span> IOException &#123;<br>        <span class="hljs-type">InputStream</span> <span class="hljs-variable">in</span> <span class="hljs-operator">=</span> <span class="hljs-literal">null</span>;<br>        <span class="hljs-keyword">try</span> &#123;<br>            in = <span class="hljs-keyword">new</span> <span class="hljs-title class_">FileInputStream</span>(outPutPath+fileName+<span class="hljs-string">&quot;.csv&quot;</span>);<br>            <span class="hljs-type">int</span> <span class="hljs-variable">len</span> <span class="hljs-operator">=</span> <span class="hljs-number">0</span>;<br>            <span class="hljs-type">byte</span>[] buffer = <span class="hljs-keyword">new</span> <span class="hljs-title class_">byte</span>[<span class="hljs-number">1024</span>];<br> <br>            <span class="hljs-type">OutputStream</span> <span class="hljs-variable">out</span> <span class="hljs-operator">=</span> response.getOutputStream();<br>            response.setContentType(<span class="hljs-string">&quot;application/csv;charset=UTF-8&quot;</span>);<br>            response.setHeader(<span class="hljs-string">&quot;Content-Disposition&quot;</span>,<span class="hljs-string">&quot;attachment; filename=&quot;</span> + URLEncoder.encode(fileName+<span class="hljs-string">&quot;.csv&quot;</span>, <span class="hljs-string">&quot;UTF-8&quot;</span>));<br>            response.setCharacterEncoding(<span class="hljs-string">&quot;UTF-8&quot;</span>);<br>            <span class="hljs-keyword">while</span> ((len = in.read(buffer)) &gt; <span class="hljs-number">0</span>) &#123;<br>                out.write(<span class="hljs-keyword">new</span> <span class="hljs-title class_">byte</span>[] &#123; (<span class="hljs-type">byte</span>) <span class="hljs-number">0xEF</span>, (<span class="hljs-type">byte</span>) <span class="hljs-number">0xBB</span>, (<span class="hljs-type">byte</span>) <span class="hljs-number">0xBF</span> &#125;);<br>                out.write(buffer, <span class="hljs-number">0</span>, len);<br>            &#125;<br>            out.close();<br>        &#125; <span class="hljs-keyword">catch</span> (FileNotFoundException e) &#123;<br>            <span class="hljs-comment">//log.error(&quot;error：&#123;&#125;&quot;, e);</span><br>        &#125; <span class="hljs-keyword">finally</span> &#123;<br>            <span class="hljs-keyword">if</span> (in != <span class="hljs-literal">null</span>) &#123;<br>                <span class="hljs-keyword">try</span> &#123;<br>                    in.close();<br>                &#125; <span class="hljs-keyword">catch</span> (Exception e) &#123;<br>                   <span class="hljs-comment">// log.error(&quot;error：&#123;&#125;&quot;, e);</span><br>                &#125;<br>            &#125;<br>        &#125;<br>        <span class="hljs-type">File</span> <span class="hljs-variable">csvFile</span> <span class="hljs-operator">=</span> <span class="hljs-literal">null</span>;<br>        csvFile =<span class="hljs-keyword">new</span> <span class="hljs-title class_">File</span>(outPutPath+fileName+<span class="hljs-string">&quot;.csv&quot;</span>);<br>        <span class="hljs-keyword">if</span>(csvFile.exists())&#123;<br>            csvFile.delete();<br>        &#125;<br>        csvFile.delete();<br>    &#125;<br> <br> <br> <br>    <span class="hljs-comment">/**</span><br><span class="hljs-comment">     * 读取csv文件</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> file</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@return</span></span><br><span class="hljs-comment">     * <span class="hljs-doctag">@throws</span> IOException</span><br><span class="hljs-comment">     */</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> List&lt;String&gt; <span class="hljs-title function_">readCsv</span><span class="hljs-params">(MultipartFile file)</span> <span class="hljs-keyword">throws</span> IOException &#123;<br> <br>        checkFile(file);<br> <br>        List&lt;String&gt; list = <span class="hljs-keyword">new</span> <span class="hljs-title class_">ArrayList</span>&lt;String&gt;();<br>        <span class="hljs-keyword">if</span> (!file.isEmpty())&#123;<br>            <span class="hljs-type">InputStreamReader</span> <span class="hljs-variable">isr</span> <span class="hljs-operator">=</span> <span class="hljs-literal">null</span>;<br>            <span class="hljs-type">BufferedReader</span> <span class="hljs-variable">br</span> <span class="hljs-operator">=</span> <span class="hljs-literal">null</span>;<br>            <span class="hljs-keyword">try</span> &#123;<br>                isr = <span class="hljs-keyword">new</span> <span class="hljs-title class_">InputStreamReader</span>(file.getInputStream());<br>                br = <span class="hljs-keyword">new</span> <span class="hljs-title class_">BufferedReader</span>(isr);<br>                <span class="hljs-type">String</span> <span class="hljs-variable">line</span> <span class="hljs-operator">=</span> <span class="hljs-literal">null</span>;<br>                List&lt;List&lt;String&gt;&gt; strs = <span class="hljs-keyword">new</span> <span class="hljs-title class_">ArrayList</span>&lt;List&lt;String&gt;&gt;();<br>                <span class="hljs-keyword">while</span> ((line = br.readLine()) != <span class="hljs-literal">null</span>)&#123;<br>                    strs.add(Arrays.asList(line.split(<span class="hljs-string">&quot;,&quot;</span>,-<span class="hljs-number">1</span>)));<br>                &#125;<br>                <span class="hljs-type">JSONArray</span> <span class="hljs-variable">array</span> <span class="hljs-operator">=</span> toJsonArray(strs);<br>                list = array.toJavaList(String.class);<br>            &#125; <span class="hljs-keyword">catch</span> (IOException e) &#123;<br>                <span class="hljs-comment">//log.error(&quot;error：&#123;&#125;&quot;, e);</span><br>            &#125;<span class="hljs-keyword">finally</span> &#123;<br>                <span class="hljs-keyword">try</span> &#123;<br>                    <span class="hljs-keyword">if</span> (br != <span class="hljs-literal">null</span>)&#123;<br>                        br.close();<br>                    &#125;<br>                    <span class="hljs-keyword">if</span> (isr != <span class="hljs-literal">null</span>)&#123;<br>                        isr.close();<br>                    &#125;<br>                &#125; <span class="hljs-keyword">catch</span> (IOException e) &#123;<br>                    <span class="hljs-comment">//log.error(&quot;error：&#123;&#125;&quot;, e);</span><br>                &#125;<br>            &#125;<br>        &#125;<span class="hljs-keyword">else</span> &#123;<br>            System.out.println(<span class="hljs-string">&quot;文件为空！&quot;</span>);<br>        &#125;<br>        <span class="hljs-keyword">return</span> list;<br>    &#125;<br> <br>    <span class="hljs-comment">/**</span><br><span class="hljs-comment">     * 读取csv文件</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> file</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@return</span></span><br><span class="hljs-comment">     * <span class="hljs-doctag">@throws</span> IOException</span><br><span class="hljs-comment">     */</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> List&lt;String[]&gt; readCsvFile(MultipartFile file ,String codeFormat) <span class="hljs-keyword">throws</span> IOException &#123;<br> <br>        checkFile(file);<br> <br>        List&lt;String[]&gt; strs = <span class="hljs-keyword">new</span> <span class="hljs-title class_">ArrayList</span>&lt;String[]&gt;();<br>        <span class="hljs-keyword">if</span> (!file.isEmpty())&#123;<br>            <span class="hljs-type">InputStreamReader</span> <span class="hljs-variable">isr</span> <span class="hljs-operator">=</span> <span class="hljs-literal">null</span>;<br>            <span class="hljs-type">BufferedReader</span> <span class="hljs-variable">br</span> <span class="hljs-operator">=</span> <span class="hljs-literal">null</span>;<br>            <span class="hljs-keyword">try</span> &#123;<br>                isr = <span class="hljs-keyword">new</span> <span class="hljs-title class_">InputStreamReader</span>(file.getInputStream(),codeFormat);<br>                br = <span class="hljs-keyword">new</span> <span class="hljs-title class_">BufferedReader</span>(isr);<br>                <span class="hljs-type">String</span> <span class="hljs-variable">line</span> <span class="hljs-operator">=</span> <span class="hljs-literal">null</span>;<br> <br>                <span class="hljs-keyword">while</span> ((line = br.readLine()) != <span class="hljs-literal">null</span>)&#123;<br>                    strs.add(line.split(<span class="hljs-string">&quot;,&quot;</span>,-<span class="hljs-number">1</span>));<br>                &#125;<br>            &#125; <span class="hljs-keyword">catch</span> (IOException e) &#123;<br>               <span class="hljs-comment">// log.error(&quot;error：&#123;&#125;&quot;, e);</span><br>            &#125;<span class="hljs-keyword">finally</span> &#123;<br>                <span class="hljs-keyword">try</span> &#123;<br>                    <span class="hljs-keyword">if</span> (br != <span class="hljs-literal">null</span>)&#123;<br>                        br.close();<br>                    &#125;<br>                    <span class="hljs-keyword">if</span> (isr != <span class="hljs-literal">null</span>)&#123;<br>                        isr.close();<br>                    &#125;<br>                &#125; <span class="hljs-keyword">catch</span> (IOException e) &#123;<br>                    <span class="hljs-comment">//log.error(&quot;error：&#123;&#125;&quot;, e);</span><br>                &#125;<br>            &#125;<br>        &#125;<span class="hljs-keyword">else</span> &#123;<br>            System.out.println(<span class="hljs-string">&quot;文件为空！&quot;</span>);<br>        &#125;<br>        <span class="hljs-keyword">return</span> strs;<br>    &#125;<br> <br> <br>    <span class="hljs-keyword">private</span> <span class="hljs-keyword">static</span> JSONArray <span class="hljs-title function_">toJsonArray</span><span class="hljs-params">(List&lt;List&lt;String&gt;&gt; strs)</span> &#123;<br>        <span class="hljs-type">JSONArray</span> <span class="hljs-variable">array</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">JSONArray</span>();<br>        <span class="hljs-keyword">for</span> (<span class="hljs-type">int</span> <span class="hljs-variable">i</span> <span class="hljs-operator">=</span> <span class="hljs-number">1</span>; i &lt; strs.size(); i++) &#123;<br>            <span class="hljs-type">JSONObject</span> <span class="hljs-variable">object</span> <span class="hljs-operator">=</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">JSONObject</span>();<br>            <span class="hljs-keyword">for</span> (<span class="hljs-type">int</span> <span class="hljs-variable">j</span> <span class="hljs-operator">=</span> <span class="hljs-number">0</span>; j &lt; strs.get(<span class="hljs-number">0</span>).size(); j++) &#123;<br>                object.put(strs.get(<span class="hljs-number">0</span>).get(j), strs.get(i).get(j));<br>            &#125;<br>            array.add(object);<br>        &#125;<br>        <span class="hljs-keyword">return</span> array;<br>    &#125;<br>    <span class="hljs-comment">/**</span><br><span class="hljs-comment">     * 检查文件格式</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@param</span> file</span><br><span class="hljs-comment">     * <span class="hljs-doctag">@throws</span> IOException</span><br><span class="hljs-comment">     */</span><br>    <span class="hljs-keyword">public</span> <span class="hljs-keyword">static</span> <span class="hljs-keyword">void</span> <span class="hljs-title function_">checkFile</span><span class="hljs-params">(MultipartFile file)</span> <span class="hljs-keyword">throws</span> IOException &#123;<br>        <span class="hljs-comment">// 判断文件是否存在</span><br>        <span class="hljs-keyword">if</span> (<span class="hljs-literal">null</span> == file) &#123;<br>            <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">FileNotFoundException</span>(<span class="hljs-string">&quot;判断文件不存在&quot;</span>);<br>        &#125;<br>        <span class="hljs-comment">// 获得文件名</span><br>        <span class="hljs-type">String</span> <span class="hljs-variable">fileName</span> <span class="hljs-operator">=</span> file.getOriginalFilename();<br>        <span class="hljs-comment">// 判断文件是否是excel文件</span><br>        <span class="hljs-keyword">if</span> (!fileName.endsWith(CSV_LOWER) &amp;&amp; !fileName.endsWith(CSV)) &#123;<br>            <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">IOException</span>(fileName + <span class="hljs-string">&quot;不是csv文件&quot;</span>);<br>        &#125;<br>    &#125;<br> <br>&#125;<br></code></pre></td></tr></table></figure>

<blockquote>
<p>来源 <a target="_blank" rel="noopener" href="https://blog.csdn.net/makabakakabuda/article/details/118914193">https://blog.csdn.net/makabakakabuda/article/details/118914193</a></p>
</blockquote>

                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/fx-blog/categories/%E5%BC%80%E5%8F%91/" class="category-chain-item">开发</a>
  
  
    <span>></span>
    
  <a href="/fx-blog/categories/%E5%BC%80%E5%8F%91/%E7%AC%94%E8%AE%B0/" class="category-chain-item">笔记</a>
  
  

  

      </span>
    
  
</span>

    </div>
  
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>8-26比赛感悟</div>
      <div>https://ray_hughes.gitee.io/fx-blog/2023/08/27/8-26比赛感悟/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>Ray_Hughes</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2023年8月26日</div>
        </div>
      
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a class="print-no-link" target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/fx-blog/2023/08/27/%E5%9B%BE%E5%BA%8A%E4%B8%8E%E5%BF%AB%E9%80%9F%E6%8F%90%E4%BA%A4%E5%9B%BE%E7%89%87/" title="图床与快速提交图片">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">图床与快速提交图片</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/fx-blog/2023/08/26/MacForJava/" title="MacForJava - 写给喵的入门手册">
                        <span class="hidden-mobile">MacForJava - 写给喵的入门手册</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
  
  
    <article id="comments" lazyload>
      
  <div id="twikoo"></div>
  <script type="text/javascript">
    Fluid.utils.loadComments('#comments', function() {
      Fluid.utils.createScript('https://lib.baomitu.com/twikoo/1.6.8/twikoo.all.min.js', function() {
        var options = Object.assign(
          {"envId":"https://twikoo.bingzi.online","region":"ap-shanghai","path":"window.location.pathname"},
          {
            el: '#twikoo',
            path: 'window.location.pathname',
            onCommentLoaded: function() {
              Fluid.utils.listenDOMLoaded(function() {
                var imgSelector = '#twikoo .tk-content img:not(.tk-owo-emotion)';
                Fluid.plugins.imageCaption(imgSelector);
                Fluid.plugins.fancyBox(imgSelector);
              });
            }
          }
        )
        twikoo.init(options)
      });
    });
  </script>
  <noscript>Please enable JavaScript to view the comments</noscript>


    </article>
  


          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header">
    <i class="iconfont icon-list"></i>
    <span>目录</span>
  </p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.4/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/fx-blog/js/events.js" ></script>
<script  src="/fx-blog/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/fx-blog/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.20.1/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/fx-blog/js/local-search.js" ></script>





<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/fx-blog/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
